package org.jsea.meta.api.ctrl;

import org.jsea.meta.api.bean.MetaApiFindRequest;
import org.jsea.meta.api.service.MetaApiApplicationContext;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * --.
 * *
 * author   Jiang.hy
 * create   2022-04-21
 */
@ConditionalOnBean(value = MetaApiApplicationContext.class)
@ConditionalOnProperty(name = "meta-api.find-enabled", matchIfMissing = true)
@RestController(value = "MetaApiController$Find")
class MetaApiController$Find extends MetaApiController {

    @PostMapping(value = "/{from}/find")
    public Object find(@RequestBody MetaApiFindRequest request,
                       @PathVariable("from") String from,
                       HttpServletRequest req,
                       HttpServletResponse res) {
        request.setFrom(from);
        return service.result.apply(service.find(request, req, res));
    }
}
